package com.naml.h_objectstream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/24 21:14
 * @desc 对象输入流，用于反序列化操作
 */
@SuppressWarnings("all")
public class ObjectInputStream02 {
    public static void main(String[] args) {
        //可以通过diaGrams查看对象输出流，其实也是利用了修饰器设计模式
        String path = "/Users/marin/xulie.dat";
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(path));
            //反序列化的时候需要与序列化数据的时候保持一致
            System.out.println(ois.readInt());
            System.out.println(ois.readBoolean());
            System.out.println(ois.readChar());
            System.out.println(ois.readUTF());
            System.out.println(ois.readDouble());
            System.out.println(ois.readFloat());
            System.out.println(ois.readLong());
            System.out.println(ois.readObject());
        }catch (IOException e){
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                ois.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
